package com.dragon.upms.biz.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dragon.common.core.util.R;
import com.dragon.common.security.annotation.Inner;
import com.dragon.upms.api.dto.UserDTO;
import com.dragon.upms.api.entity.SysUser;
import com.dragon.upms.biz.service.SysUserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @date: 2024/8/5 22:22
 * @author: ybl
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user")
//@Tag(description = "user", name = "用户管理模块")
public class SysUserController {

    private final SysUserService userService;

    @PostMapping
    public R user(@RequestBody UserDTO userDTO) {
        return R.success(R.success(userService.saveUser(userDTO)));
    }

    @Inner
    @GetMapping(value = { "/info/query" })
    public R info(@RequestParam(required = false) String username, @RequestParam(required = false) String phone) {
        SysUser user = userService.getOne(Wrappers.<SysUser>query()
                .lambda()
                .eq(StrUtil.isNotBlank(username), SysUser::getUsername, username)
                .eq(StrUtil.isNotBlank(phone), SysUser::getPhone, phone));
        if (user == null) {
            return R.fail("info_失败");
//            return R.fail(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERINFO_EMPTY, username));
        }
        return R.success(userService.findUserInfo(user));
    }
}
